package com.aspose.cells.b.a.b;

import com.aspose.cells.ImageFormat;
import com.aspose.cells.a.d.zaj;
import com.aspose.cells.a.d.zat;
import com.aspose.cells.a.d.zbn;
import com.aspose.cells.a.d.zch;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;

public abstract class zj {
   protected BufferedImage a = null;
   protected ImageFormat b;
   protected zs c;
   protected float d = 96.0F;
   protected float e = 96.0F;
   public byte[] f;

   protected zj() {
   }

   protected zj(BufferedImage var1, ImageFormat var2) {
      this.a(var1, var2);
   }

   public abstract zj a();

   public void d() {
      this.a = null;
   }

   public ImageFormat e() {
      return this.b;
   }

   public static zj a(String var0) throws Exception {
      return new za(var0);
   }

   public static zj a(com.aspose.cells.b.a.d.zm var0) throws Exception {
      switch(zbn.a(var0)) {
      case 1:
      case 2:
         return new com.aspose.cells.b.a.b.b.zf(var0);
      default:
         return new za(var0);
      }
   }

   protected void a(BufferedImage var1, ImageFormat var2) {
      this.a = var1;
      this.c = new zs(this.a.getWidth(), this.a.getHeight());
      this.b = var2;
   }

   public void b() {
   }

   public BufferedImage f() {
      if (this.a != null) {
         return this.a;
      } else {
         if (this.f != null) {
            int var1 = this.i();
            int var2 = this.h();
            if (var1 < 0) {
               var1 = 1;
            }

            if (var2 < 0) {
               var2 = 1;
            }

            zo var3 = new zo(0.0F, 0.0F);
            zt var4 = new zt(this.a((float)var1), this.a((float)var2));
            com.aspose.cells.a.d.zm var5 = new com.aspose.cells.a.d.zm(var4);
            com.aspose.cells.a.d.zj var6 = new com.aspose.cells.a.d.zj(var3, var4, this.f);

            try {
               com.aspose.cells.a.d.zb var7 = zch.a(var6);
               var5.a(var7);
               this.a = new BufferedImage(var1, var2, 5);
               Graphics2D var8 = this.a.createGraphics();
               zat var9 = new zat();
               var9.a(var5, var8, 0.0F, 0.0F, 1.0F);
            } catch (Exception var10) {
               var10.printStackTrace();
            }
         }

         return this.a;
      }
   }

   private float a(float var1) {
      return (float)zaj.c((double)var1);
   }

   public void a(float var1, float var2) {
      this.d = var1;
      this.e = var2;
   }

   public int g() {
      int var1 = 0;
      if (this.a.isAlphaPremultiplied()) {
         var1 |= 2;
      }

      boolean var2 = true;
      int var4 = this.a.getTransparency();
      if (var4 == 3) {
         var1 |= 4;
      }

      int var3 = this.a.getType();
      switch(var3) {
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
         var1 |= 16;
         break;
      case 10:
      case 11:
         var1 |= 64;
      }

      if (var3 == 5) {
         var1 |= 4;
      }

      return var1;
   }

   public int h() {
      return this.a.getHeight();
   }

   public int i() {
      return this.a.getWidth();
   }

   public float j() {
      return this.d;
   }

   public float k() {
      return this.e;
   }

   public com.aspose.cells.b.a.b.b.za l() {
      throw new com.aspose.cells.a.c.zb("");
   }

   public int c() {
      return 139273;
   }

   public static int a(int var0) {
      return 24;
   }

   public zs m() {
      return this.c;
   }

   public static boolean b(int var0) {
      switch(var0) {
      case 397319:
      case 925707:
      case 2498570:
         return true;
      default:
         return false;
      }
   }

   public void a(com.aspose.cells.b.a.d.zm var1, ImageFormat var2) throws Exception {
      this.a(var1.j(), var2);
   }

   public void a(String var1, ImageFormat var2) throws Exception {
      FileOutputStream var3 = new FileOutputStream(var1);
      this.a((OutputStream)var3, var2);
      var3.flush();
      var3.close();
   }

   private void a(OutputStream var1, ImageFormat var2) throws Exception {
      String var3 = ImageFormat.a(var2);
      if (var3 == null) {
         var3 = "BMP";
      }

      ImageIO.write(this.a, var3, var1);
      var1.flush();
   }
}
